home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 34 / Mac Magazin and MacEasy Magazine CD - Issue 34.iso / Grafik & Text / Alpha ƒ / Tcl / Modes / setextMode.tcl < prev    next >
Text File  |  1996-08-15  |  1KB  |  51 lines

  1. #################################################################################
  2. # Setext file support
  3. #
  4. # Recognize and automatically mark 'setext'-encoded text files, like Tidbits.
  5. #
  6. # (Tom Pollard - October 1994)
  7. #
  8. #================================================================================
  9.  
  10.  
  11. if {$startingUp} {
  12.     addMode Setx dummySetx {*.stx *.etx} {}
  13.     return
  14. }
  15.  
  16. #===============================================================================
  17.  
  18.  
  19.  
  20. newModeVar Setx autoMark    1    1
  21. #=============================================================================
  22. proc dummySetx {} {}
  23.  
  24. proc SetxMarkFile {} {
  25.     set pat1 {^(-+|=+)$}
  26.     set end [maxPos]
  27.     set pos 0
  28.     set l {}
  29.     while {![catch {search -f 1 -r 1 -m 0 -i 1 $pat1 $pos} mtch]} {
  30.         set pos1 [lineStart [expr [lindex $mtch 0] - 1]]
  31.         set marker [string trimright [eval getText $mtch]]
  32.         set text [string trimright [getText $pos1 [nextLineStart $pos1]]]
  33.         if {[string length $text] == [string length $marker]} {
  34.             if {[string range $marker 0 0] == "-"} {
  35.                 set text "     $text"
  36.             }
  37.             regsub {/} $text {-} text
  38.             set inds($text) $pos1
  39.             lappend sects $text
  40.         }
  41.         set pos [nextLineStart [lindex $mtch 1]]
  42.     }
  43.  
  44.     if {[info exists inds]} {
  45.         foreach f $sects {
  46.             set next [lineStart $inds($f)]
  47.             setNamedMark $f $inds($f) $next $next
  48.         }
  49.     }
  50. }
  51.